<?php
/***********************************************************************

  Copyright (C) 2008  Fabrice douteaud (fdouteaud@gmail.com)

    This file is part of ClearBudget.

    ClearBudget is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClearBudget is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.


************************************************************************/
$db = class_db::getInstance();
// get all the categories but the 'uncategorized' one
$db->addFields('id');
$db->addFields('name');
$db->addWhere('id', '!=', '1');
// execute
$db->select('v_categories');
while(($item = $db->fetchRow()) !== false) {
  $categories[$item['id']] = $item['name'];
  }
// setup the query
$db->addFields('id');
$db->addFields('operationDate');
$db->addFields('category');
$db->addFields('categoryName');
$db->addFields('amount');
$db->addFields('debit');
$db->addFields('payee');
$db->addFields('memo');
$db->addFields('comments');
$db->addWhere('id', '=', $_GET['id']);
$count = $db->select('v_items', true);
$result = $db->fetchRow();

?>
<div class="title"><?php echo $keys->pageEditItemTitle; ?></div><br/>
<form action="index.php" method="post">
<input type="hidden" name="action" value="itemEditSubmit">
<table class="tableReport" onMouseOver="javascript:trackTableHighlight(event, '#E6EAE9');" onMouseOut="javascript:highlightTableRow(0);">
<tr>
  <th><?php echo $keys->settingName; ?></th>
  <th><?php echo $keys->settingInput; ?></th>
</tr>
<tr><td><?php echo $keys->operationDate; ?></td>
<td><?php echo $result['operationDate']?></td></tr>
<tr><td><?php echo $keys->amountLong; ?></td>
<td><?php echo $result['amount']?> (<?php echo class_settings::$currency?>)</td></tr>
<tr><td><?php echo $keys->payee; ?></td>
<td><?php echo $result['payee']?></td></tr>
<tr><td><?php echo $keys->memo; ?></td>
<td><?php echo $result['memo']?></td></tr>
<tr><td><?php echo $keys->commentsLong; ?></td>
<td><input type="text" size="50" value="<?php echo $result['comments']?>" name="comment" id="comment"></td></tr>
<tr><td><?php echo $keys->categoryNameLong; ?></td>
<td><select class="selectCategory"><option value="0"><?php echo $keys->pickInTheList ?></option>
<?php foreach($categories as $id=>$name){
    echo '<option value="'.$id.'"';
    if($result['category'] == $id) echo ' selected="selected"';
    echo '>'.$name.'</option>';
    }
?>
</select></td></tr>
<tr><td colspan="2"  style="text-align:center" ><input type="submit" class="submit" name="submit" value="Go"></td></tr>
</table>
</form>
